<img src="./themes/<?=$theme?>/img/blank.png" onLoad="updateTrafLogger(); trafLoggerInterval = setInterval('updateTrafLogger()', 9000);" />
<div id="trafLogger"></div>
<div class="helpInfo" onClick="showAirExport()">export playlist</div>
<div id="airExport"></div>
<br /><?php 

$alphabet = array('#','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
?><form action="<?=$HOME_?>" method="post">
<?php
foreach ($alphabet as $alpha) {
	echo ('<a href="'.$HOME_.'?mode=cdlist&artistbeginwith='.$alpha.'">'.strtoupper($alpha).'</a> ');
}
?>
</form><br />
<?php

//reinitialize a few variables:
if ($_POST['slot']) {
	$slot = $_POST['slot'];
	if (ctype_alpha($slot[(strlen($slot)-1)])) {  //this is a nice lil' hack to get multi-disc CDs to use the same slot number, this portion trims the trailing A, B, C, etc from the slot number...
		$multi_ID = $slot[(strlen($slot)-1)]; //normally we would make this string upper here, but we need to trim the character from the slot no matter the case, so we'll wait until after the next statement
		$slot = rtrim($slot, $multi_ID);  // cut that alpha variable off my integer!!!
		$multi_ID = strtoupper($multi_ID);  // capitalize that alphabetical multiple CD delimiter!
	}
}
if ($_REQUEST['trackno']) $trackno = $_REQUEST['trackno'];
if ($_POST['cd_new']) $cd_new = $_POST['cd_new'];
if ($_POST['request']) $request = 1;
if ($_REQUEST['cddbid']) $cddbid = $_REQUEST['cddbid'];
if ($_REQUEST['trkId']) $trkId = $_REQUEST['trkId'];
//end variable crap

if (($cd_new == "") || ($cd_new =="0") || ($cd_new == 'false')) {
	unset($cd_new);
}
if ( ($do === 'add_event_to_traffic') && ($_REQUEST[eventtype]) ) {
	mysql_query("INSERT INTO `traffic` 
		SET `timestamp`='".mysql_real_escape_string($nowstamp)."', 
		`comment`='".mysql_real_escape_string($_REQUEST['comment'])."',
		`user`='".mysql_real_escape_string($U_id)."',
		`eventtype`='".mysql_real_escape_string($_REQUEST['eventtype'])."',
		`sched_id`='".mysql_real_escape_string($_REQUEST['sched_id'])."' ") or die(mysql_error());
	echo("event added.");
	mysql_query("UPDATE `schedule` SET  `completed`='1' WHERE `id`='".mysql_real_escape_string($_REQUEST['sched_id'])."' ") or die(mysql_error());
} elseif ($do === 'air_add'){
	
/* this could come in handy later
	$logstamp = date("Y-m-d H:i:s");
	if ($_GET['cddbid'] && $_GET['trackno']){
		mysql_select_db($DB_NAME, $view_connect);
		$albumrow = mysql_fetch_row(mysql_query("SELECT `cddbid`,`slot`,`tracks`,`status`,`title`,`artist` FROM `album` WHERE `cddbid` = '".$_GET[cddbid]."' LIMIT 1"));
		$trackrow = mysql_fetch_row(mysql_query("SELECT `cddbid`,`title`,`virtue` FROM `track` WHERE (`cddbid` = '".$_GET[cddbid]."' AND `trackno` = '".$_GET['trackno']."') LIMIT 1")) or die(mysql_error());
		/// add the retrieved info to the log 
		$write_connect = mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS);
		mysql_select_db($DB_NAME, $write_connect) or die(mysql_error());
		mysql_query("INSERT INTO `airplay` (`timestamp`,`cddbid`,`slot`,`trackno`,`track`,`artist`,`album`,`request`,`status`,`user`) VALUES ('$logstamp','$albumrow[0]','$albumrow[1]','".$_GET['trackno']."',\"$trackrow[1]\",\"$albumrow[5]\",\"$albumrow[4]\",'".$_GET['request']."','$albumrow[3]','$U_id')") or die(mysql_error());
		$statusmsg = 'song inserted from link';
//end this could come in handy later */

//	} else if ($_POST['slot'] && $_POST['trackno']){
//		mysql_select_db($DB_NAME, $view_connect);
//		$albumresult = mysql_query("SELECT `cddbid`,`slot`,`tracks`,`status`,`title`,`artist` from `album` WHERE (`slot`='".$_POST['slot']."' AND `category`='$cat')");

//disable this stuff until we can assure that all new CDs are in the library... 
//		while ($albumrow = mysql_fetch_row($albumresult)){
//			if ($_POST['trackno'] > $albumrow[2]){
//				print ('You fool!  There are not ' . $_POST['trackno'] . ' tracks on this album!  It only has ' . $albumrow[2] . '!');
//			} else {
//			  $trackresult = mysql_query("SELECT `cddbid`,`title`,`virtue` from `track` WHERE (`cddbid`='$albumrow[0]' AND `trackno`='".$_POST['trackno']."') LIMIT 1");
//			  $trackrow = mysql_fetch_row($trackresult);
 
			  /* add the retrieved info to the log */
//			  $write_connect = mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS);
//			  mysql_select_db($DB_NAME, $write_connect) or die('whoops');
//			  mysql_query("INSERT INTO `airplay` 
//			  		(`timestamp`,`cddbid`,`slot`,`trackno`,`track`,`artist`,`album`,`request`,`status`,`user`) 
//			  		VALUES ('$logstamp','$albumrow[0]','".$_POST['slot']."','".$_POST['trackno']."',\"$trackrow[1]\",\"$albumrow[5]\",\"$albumrow[4]\",'".$_POST['request']."','$albumrow[3]','$U_id')") or die(mysql_error());
//			}
//		}

/*  temporary solution ... it the CD is reported as "new", find the cddbid and log the slot and cddbid */
	if ( (isset($cd_new) && $slot != 0) || $trkId || (($slot) && (isset($trackno))) || $cddbid) {
		mysql_select_db($DB_NAME, mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS));
		if (!$cddbid){		//if we insert from the "traffic" mode itself, we wont have a cddbid to work with, so we're gonna look it up later
			$cd_row_query = "SELECT * FROM `album` WHERE (`slot`='".mysql_real_escape_string($slot)."') ORDER BY `status` ASC, `multi` ASC LIMIT 1";
			if ($trkId) {
   			$albIdQuery = mysql_query("SELECT `cddbid` FROM `track` WHERE `id`='".$trkId."' LIMIT 1");
	   		if ($cddbid = mysql_result($albIdQuery, 0)) {
	   		   $cd_row_query = "SELECT * FROM `album` WHERE `cddbid` = '".$cddbid."' LIMIT 1";
	   		}		
			}
		} else {	//we might, though, have a cddbid to work with, that makes things easier
			$cd_row_query = "SELECT * FROM `album` WHERE (`cddbid`='".mysql_real_escape_string($cddbid)."') LIMIT 1";
		}
		if ($multi_ID) {
			$cd_row_query = "SELECT * FROM `album` WHERE (`slot`='".mysql_real_escape_string($slot)."' AND `multi`='".mysql_real_escape_string($multi_ID)."') ORDER BY `multi` ASC LIMIT 1";
		}
		if ($cd_row = mysql_fetch_assoc(mysql_query($cd_row_query))) {
			$cddbid = $cd_row[cddbid];
			if (!$trkId) $track_row = mysql_fetch_assoc(mysql_query("SELECT `title`,`artist` FROM `track` WHERE (`cddbid`='".mysql_real_escape_string($cddbid)."') AND (`trackno`='".mysql_real_escape_string($trackno)."') LIMIT 1"));
			else $track_row = mysql_fetch_array (mysql_query("SELECT * FROM `track` WHERE `id`='".$trkId."' LIMIT 1"));
			if (!$track_row[trackno]) $track_row[trackno] = $_REQUEST[trackno];
			if ($cd_row[is_comp] && $track_row[artist]) $cd_row[artist] = $track_row[artist];
		}
		if ($cddbid) {
			if (!$track_row[title]) $track_row[title] = $_REQUEST['artist'];
			mysql_query(
			"INSERT INTO `airplay` 
			SET 
			`timestamp`='".mysql_real_escape_string($nowstamp)."',
			`status`='".mysql_real_escape_string($cd_row[status])."',
			`slot`='".mysql_real_escape_string($cd_row[slot])."',
			`cddbid`='".mysql_real_escape_string($cd_row[cddbid])."',
			`trackno`='".mysql_real_escape_string($track_row[trackno])."',
			`user`='".mysql_real_escape_string($U_id)."',
			`track`='".mysql_real_escape_string($track_row[title])."',
			`artist`='".mysql_real_escape_string($cd_row[artist])."',
			`album`='".mysql_real_escape_string($cd_row[title])."',
			`request`='".mysql_real_escape_string($request)."',
			`category`='".$cd_row[category]."',
			`category2`='".$cd_row[category2]."',
			`category3`='".$cd_row[category3]."',
         `add_date`='$cd_row[add_date]'
			") or die(mysql_error());
			$cdadded = 1;
		}
	}
	if (!$slot) $slot = $_POST['slot'];
	if (!$status) {
		if ($cd_new) {
		$status = 2;
		} else {
			$status = 0;
		}
	}
	if (!$cdadded) {
		$write_connect = mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS);
		mysql_select_db($DB_NAME, $write_connect);
		mysql_query("
		INSERT INTO `airplay` 
		SET 
		`timestamp`='".mysql_real_escape_string($nowstamp)."',
		`status`='".mysql_real_escape_string($status)."',
		`slot`='".mysql_real_escape_string($slot)."', 
		`cddbid`='".mysql_real_escape_string($cddbid)."',
		`trackno`='".mysql_real_escape_string($trackno)."',
		`user`='".mysql_real_escape_string($U_id)."',
		`track`='".mysql_real_escape_string($_POST['track'])."',
		`artist`='".mysql_real_escape_string($_POST['artist'])."',
		`album`='".mysql_real_escape_string($_POST['album'])."',
		`request`='".mysql_real_escape_string($request)."'
		 ") or die(mysql_error());
	}
$statusmsg = 'song inserted from form';
} elseif ($do === 'air_delete') {
	mysql_select_db($DB_NAME, mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS));
	mysql_query("DELETE FROM `airplay` WHERE (`timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' AND `user`='".mysql_real_escape_string($U_id)."') LIMIT 1") or die(mysql_error());
} elseif ($do === 'air_down') {
	$airstamp = mysql_fetch_assoc(mysql_query("SELECT `id`,`timestamp` FROM `airplay` WHERE (`timestamp`<'".mysql_real_escape_string($_GET['timestamp'])."' AND (`user`='".mysql_real_escape_string($U_id)."')) ORDER BY `timestamp` DESC LIMIT 1"));
	$trafficstamp = mysql_fetch_assoc(mysql_query("SELECT `id`,`timestamp` FROM `traffic` WHERE (`timestamp`<'".mysql_real_escape_string($_GET['timestamp'])."' AND (`user`='".mysql_real_escape_string($U_id)."')) ORDER BY `timestamp` DESC LIMIT 1"));
	$moved_air_id = mysql_result(mysql_query("SELECT `id` FROM `airplay` WHERE `timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' AND (`user`='".mysql_real_escape_string($U_id)."') LIMIT 1"), 0);
	if ($trafficstamp[timestamp] < $airstamp[timestamp]) {
		mysql_query("UPDATE `airplay` SET `timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' WHERE `id`='".mysql_real_escape_string($airstamp[id])."' AND (`user`='".mysql_real_escape_string($U_id)."') ");
		mysql_query("UPDATE `airplay` SET `timestamp`='".mysql_real_escape_string($airstamp[timestamp])."' WHERE `id`='".mysql_real_escape_string($moved_air_id)."' AND (`user`='".mysql_real_escape_string($U_id)."') ");
	} else {
		mysql_query("UPDATE `traffic` SET `timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' WHERE `id`='".mysql_real_escape_string($trafficstamp[id])."' AND (`user`='".mysql_real_escape_string($U_id)."') ");
		mysql_query("UPDATE `airplay` SET `timestamp`='".mysql_real_escape_string($trafficstamp[timestamp])."' WHERE `id`='".mysql_real_escape_string($moved_air_id)."' ");
	}
} elseif ($do === 'traffic_down') {
	$airstamp = mysql_fetch_assoc(mysql_query("SELECT `id`,`timestamp` FROM `airplay` WHERE (`timestamp`<'".mysql_real_escape_string($_GET['timestamp'])."' AND (`user`='".mysql_real_escape_string($U_id)."')) ORDER BY `timestamp` DESC LIMIT 1"));
	$trafficstamp = mysql_fetch_assoc(
		mysql_query("
			SELECT `id`,`timestamp` FROM `traffic` 
			WHERE (`timestamp`<'".mysql_real_escape_string($_GET['timestamp'])."' 
			AND (`user`='".mysql_real_escape_string($U_id)."')) 
			ORDER BY `timestamp` DESC LIMIT 1")
			);
	$moved_traffic_id = mysql_result(mysql_query("SELECT `id` FROM `traffic` WHERE `timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' AND (`user`='".mysql_real_escape_string($U_id)."') LIMIT 1"), 0);
	if ($trafficstamp[timestamp] < $airstamp[timestamp]) {
		mysql_query("UPDATE `airplay` SET `timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' WHERE `id`='".mysql_real_escape_string($airstamp[id])."' AND (`user`='".mysql_real_escape_string($U_id)."') ");
		mysql_query("UPDATE `traffic` SET `timestamp`='".mysql_real_escape_string($airstamp[timestamp])."' WHERE `id`='".mysql_real_escape_string($moved_traffic_id)."'  AND (`user`='".mysql_real_escape_string($U_id)."') ");
	} else {
		mysql_query("UPDATE `traffic` SET `timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' WHERE `id`='".mysql_real_escape_string($trafficstamp[id])."' AND (`user`='".mysql_real_escape_string($U_id)."') ");
		mysql_query("UPDATE `traffic` SET `timestamp`='".mysql_real_escape_string($trafficstamp[timestamp])."' WHERE `id`='".mysql_real_escape_string($moved_traffic_id)."' AND (`user`='".mysql_real_escape_string($U_id)."') ");
	}
} elseif ($do === 'air_edit') {
	$AirItem = mysql_fetch_array(mysql_query("SELECT * FROM `airplay` 
		WHERE (`timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' 
		AND `user`='".mysql_real_escape_string($U_id)."') LIMIT 1"));
		if ($AirItem) echo($AirItem[0]);
	?>
	<span style="font-weight: bold;">Update/Correct Information:</span><br />
	<form action="<?=$HOME_?>" method="post">
	<table>
	<tr><th>Slot</th><th>Track</th><th>Title</th><th>Artist</th><th>Album</th><th>Age</th><th>Time</th></tr>
	<tr>
		<td><input type="text" size="4" name="slot" value="<?=$AirItem['slot']?>" /></td>
		<td><input type="text" size="3" name="trackno" value="<?=$AirItem['trackno']?>" /></td>
		<td><input type="text" name="track" value="<?=$AirItem['track']?>" /></td>
		<td><input type="text" name="artist" value="<?=$AirItem['artist']?>" /></td>
		<td><input type="text" name="album" value="<?=$AirItem['album']?>" /></td>
		<td><select name="age"><option value="2">New</option><option value="3">Old</option></select></td>
		<td><input type="text" name="time" value="<?=date('H:i:s', $AirItem['timestamp'])?>" /></td>
	</tr>
	</table>
	<select name="category">
	<option value="">unknown</option><?php
		$category_query = "SELECT `id`,`category`,`default` FROM `category` ORDER BY `category`";
		$category_result = mysql_query($category_query);
		while ($category_row = mysql_fetch_row($category_result)) {
		?><option value="<?=$category_row[0]?>"<?php 
		if ($category_row[0] === $AirItem[category]) {
			print(' selected="selected" ');
		} elseif ($category_row[2]){
			print(' selected="selected"');
		}
		?>><?=$category_row[1]?></option>
		<?php
	}
	?>
	</select>
	<input type="hidden" name="id" value="" />
	<input type="hidden" name="datestamp" value="<?=date('Y-m-d', $AirItem['timestamp'])?>" />
	<input type="hidden" name="cddbid" value="" />
	<input type="hidden" name="user" value="" />
	<input type="checkbox" name="disable_lookup" value="true" disabled="disabled">Disable data lookup and correction</input>
	<input type="hidden" name="cat" value="<?=$cat?>" />
	<input type="hidden" name="do" value="post_air_edit" />
	<input type="hidden" name="mode" value="traffic" />
	<br /><input type="submit" value="Save Changes" />
	</form>
	<?php
	echo('<h3> sorry, jackson is still writing this feature!</h3>');
} elseif ($do === 'post_air_edit') {
	$timestamp = ($_POST['datestamp'] . ' ' . $_POST['time']);
	mysql_select_db($DB_NAME, mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS));
	mysql_query("
		UPDATE `airplay` SET
		`slot`='".mysql_real_escape_string($_POST['slot'])."', 
		`trackno`='".mysql_real_escape_string($_POST['trackno'])."', 
		`track`='".mysql_real_escape_string($_POST['track'])."', 
		`artist`='".mysql_real_escape_string($_POST['artist'])."', 
		`album`='".mysql_real_escape_string($_POST['album'])."', 
		`status`='".mysql_real_escape_string($_POST['age'])."', 
		`timestamp`='".mysql_real_escape_string($_POST[''])."'
		WHERE `id`='".mysql_real_escape_string($_POST['id'])."'
		");
	
	echo('<h1>sorry, editing does not work yet!</h1>');
} elseif ($do === 'traffic_delete') {
	mysql_select_db($DB_NAME, mysql_connect($DB_HOST, $DB_WRITE_USER, $DB_WRITE_USER_PASS));
	mysql_query("DELETE FROM `traffic` WHERE (`timestamp`='".mysql_real_escape_string($_GET['timestamp'])."' AND `user`='".mysql_real_escape_string($U_id)."') LIMIT 1") or die(mysql_error());
}
// This should be moved, as it goes with log display stuff
$three_hours_ago  = date('Y-m-d H:i:s' ,mktime( date('H') - 3, date('i'), date('s'), date("m"),  date("d"),  date("Y")));
mysql_select_db($DB_NAME, $view_connect);
$ten_minutes_ago  = date('Y-m-d H:i:s' ,mktime( date('H'), date('i') - 10, date('s'), date("m"),  date("d"),  date("Y")));
mysql_select_db($DB_NAME, $view_connect);
$airplaysql = "SELECT `timestamp`,`trackno`,`track`,`artist`,`album`,`request`,`status`,`slot`,`id`,`cddbid` FROM `airplay` WHERE (((`user`='".mysql_real_escape_string($U_id)."') AND (`timestamp`>'".mysql_real_escape_string($three_hours_ago)."')) OR (`timestamp`>'".mysql_real_escape_string($ten_minutes_ago)."' )) ORDER BY `timestamp` DESC";
$airplayresult = mysql_query($airplaysql) or die(mysql_error());
















//
//
// {{{}}}
// THE following lines are being removed: 
/* 
?>
<table style="background-color: #ff00ff;"><tr><td>
<table style="background-color: blue;"><tr><td>
<table style="background-color: red;">
<?php
$time_now = date('H:i:s');
$minimum_minutes_offset = 11;
$maximum_hours_offset = 1;
	$weekday = date('l');
$time_minimum  = date('H:i:s', mktime(date('H'), date('i') - $minimum_minutes_offset, date('s'), date("m"),  date("d"),  date("Y")));
$time_maximum  = date('H:i:s', mktime(date('H') + $maximum_hours_offset, date('i'), date('s'), date("m"),  date("d"),  date("Y")));
$time_maximum_from_zero = date('H:i:s', mktime($maximum_hours_offset, 0, 0, date('m'), date('d'), date('Y')));
$time_critical = date('H:i:s', mktime(24 - $maximum_hours_offset, 0, 0, date('m'), date('d'), date('Y')));
if ($time_now >= $time_critical) {
	$next_weekday = date('l', mktime(date('H'), date('i'), date('s'), date('m'), date('d')+1, date('Y')));
	$schedule_query = "SELECT * FROM `schedule` WHERE (((`day`='".mysql_real_escape_string($weekday)."')  AND (`starttime`>='".mysql_real_escape_string($time_minimum)."') AND (`starttime`<='24:00:00')) OR ((`day`='".mysql_real_escape_string($next_weekday)."') AND (`starttime`<='".mysql_real_escape_string($time_maximum_from_zero)."')))  ORDER BY `day`,`starttime` ASC";
} else {
	$schedule_query = "SELECT * FROM `schedule` WHERE (`day`='".mysql_real_escape_string($weekday)."') AND ((`starttime`>='".mysql_real_escape_string($time_minimum)."') AND (`starttime`<='".mysql_real_escape_string($time_maximum)."')) ORDER BY `starttime` ASC";
}
	$schedule_result = mysql_query($schedule_query) or die(mysql_query());
	while ($schedule_row = mysql_fetch_assoc($schedule_result)) {
		
		$event_query = "SELECT `name`,`id` FROM `event` WHERE `id`='".mysql_real_escape_string($schedule_row['eventtype'])."' LIMIT 1";
		$event_result = mysql_query($event_query);
		$assoc_result = mysql_fetch_assoc($event_result);
?>
<tr><td <?php if ($do === 'event_pre_add' && $schedule_row['id'] == $_POST['sched_id']) echo(' style="background-color: #aaaaff"') ?>>
		<?php
		echo($assoc_result['name']);
?></td><td <?php if ($do === 'event_pre_add' && $schedule_row['id'] == $_POST['sched_id']) echo(' style="background-color: #aaaaff"') ?>><?php
		$eight_minutes_ahead = date('H:i:s', mktime(date('H'), date('i')+8, date('s'), date('m'), date('d'), date('Y')));
		if (date('H:i:s', strtotime($schedule_row['starttime'])) <= $eight_minutes_ahead ) {
			echo ('<div style="color: red; font-weight: bold">');
		}
		echo (date('h:i', strtotime($schedule_row['starttime'])) );
		if (date('H:i:s', strtotime($schedule_row['starttime'])) <= $eight_minutes_ahead ) {
			echo ('</div>');
		}
		if ($schedule_row['endtime']) {
			echo ('-' . date('h:i', strtotime($schedule_row['endtime'])));
		}
?></td>
<?php if ($do !== 'event_pre_add') {
	?>
<td>
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="hidden" name="mode" value="<?=$mode?>" />
<input type="hidden" name="do" value="event_pre_add" />
<input type="hidden" name="eventtype" value="<?=$assoc_result['id']?>" />
<input type="hidden" name="sched_id" value="<?=$schedule_row['id']?>" />
<input type="submit" value="add" /></form>
<?php
}
?>
</td></tr><?php
}
?></table>

<?php
if ($do === 'event_pre_add') {
	?>
	</td><td>
	<table style="background-color: #aaaaff"><tr><td>
	<form action="<?$_SERVER['PHP_SELF']?>" method="post">
	<?php
	$event_sql = "SELECT `name` FROM `event` WHERE `id`='".mysql_real_escape_string($_POST['eventtype'])."' LIMIT 1";
	$event_result = mysql_result(mysql_query($event_sql), 0); // this will tell us what kind of event we have, if we want to echo this variable
	?>Comment/Notes: <br /><textarea name="comment"></textarea>
	<input type="hidden" name="eventtype" value="<?=$_POST['eventtype']?>" />
	<input type="hidden" name="sched_id" value="<?=$_POST['sched_id']?>" />
	<input type="hidden" name="mode" value="<?=$mode?>" />
	<input type="hidden" name="do" value="add_event_to_traffic" />
	<br />
	<input type="submit" value="Add Event" /></form><form method="post" action="<?=$_SERVER[PHP_SELF]?>" style="" name="cancel_traffic_submit"><input type="hidden" name="cat" value="<?=$cat?>" /><input type="hidden" name="mode" value="traffic" /><input type="submit" value="cancel" /></form>
	</td></tr></table>
	<?php
}
?>
</td></tr></table></td><td></td></tr></table>

<?php
*/ 

///
// END Removal
// {{{}}}
//
//



?>





















<form name="AirplayAdd" action="<?=$_SERVER[PHP_SELF]?>" method="post">
<table style="border: 2px solid black; background-color: #d6e6ff">
<tr align="center">
<td>slot</td><td>track</td><td colspan="2">track title</td><td>artist</td><td>album</td><td>new</td><td>old</td><td>req</td><td> </td></tr>
<tr>
	<td><center><input name="slot" id="trafTrkInputSlot" type="text" autocomplete="off" maxlength="6" size="3" tabindex="1" /></center></td>
	<td><center><input type="text" autocomplete="off" name="trackno" maxlength="3" size="3" tabindex="2" /></center></td>
	<td colspan="2"><input type="text" id="trafTrkInputTitle" name="track" tabindex="3"  /></td>
	<!-- onInput="parent.trafTrkAddCtxt('trk', this.value, event.clientX, event.clientY);" -->
	<td><center><input type="text" name="artist" tabindex="4" /></center></td>
	<td><center><input type="text" name="album" tabindex="5" /></center></td>
	<td><center><input type="radio" name="cd_new" value="true" tabindex="6" /></center></td>
	<td><center><input type="radio" name="cd_new" tabindex="7" value="false" /></center></td>
	<td><center><input type="checkbox" name="request" value="1" tabindex="8" /></center></td>
	<td> </td>
</tr>
<tr>
	<td colspan="8">
	<input type="hidden" name="mode" value="<?=$mode?>" />
	<input type="hidden" name="cat" value="<?=$cat?>" />
	<input type="hidden" name="do" value="air_add" />
	<input type="submit" tabindex="9" value="Add To Log" /> <input type="reset" value="cancel" tabindex="10" />	</td>
</tr>
<tr align="center" style="background-color: #7e96ba; color:white">
<td>slot</td><td>track</td><td style="width:0px;"></td><td>track title</td><td>artist</td><td>album</td><td>new</td><td>old</td><td>req</td><td>edit</td></tr>
</tr>
</form>
<form name="trafficForm">
<?php
$lasttimestamp = $nowstamp; 
$newcounter = 0;
$oldcounter = 0;
$requestcounter = 0;
$q =0; //we use this to count for element IDs to help out javascript stuff
while (($airplayrow = $airItem = mysql_fetch_array($airplayresult))) {
	//start getting info for traffic log
	$traffic_sql = "SELECT * FROM `traffic` WHERE ((`timestamp`<='".mysql_real_escape_string($lasttimestamp)."')  AND (`timestamp`>='".mysql_real_escape_string($airplayrow[0])."') AND (`user`='".mysql_real_escape_string($U_id)."')) ORDER BY `timestamp` DESC";
	$traffic_result = mysql_query($traffic_sql) or die(mysql_error());
	while($traffic_row = mysql_fetch_assoc($traffic_result)) {
		//this will give us the proper event name from the DB:
		$eventname = mysql_result(mysql_query("SELECT `name` FROM `event` WHERE `id`='".mysql_real_escape_string($traffic_row[eventtype])."' LIMIT 1"), 0);
		?>
		<?php  //begin traffic event widget
		include('./widgets/traffic_event.inc');
		// end traffic event widget
		?>
		<?php
	}
	$status = $airplayrow[6];
	if ($status == 1 || $status == 2) {
		$new = '<img height="16" width="16" alt="new checkmark" src="./themes/'.$theme.'/img/check.png" title="NEW!" />';
		$newcounter++;
		$old = '<img height="16" width="16" src="./themes/'.$theme.'/img/blank.png" alt=" " />';
	} else {
	  $old = '<img height="16" width="16" alt="old checkmark" src="./themes/'.$theme.'/img/check.png" title="old." />';
	  $new = '<img height="16" width="16" src="./themes/'.$theme.'/img/blank.png" alt=" " />';
	  $oldcounter++;
	}
	if ($airplayrow[5]) {
//		$request = '<img height="16" width="16" alt="request checkmark" src="./themes/' . $theme . '/img/check.png" title="a request!" />';
//		$request = '<input type="checkbox" id="request[' . $q . ']" onclick="if (document.getElementById(\'request[' . $q . ']\').checked) { alert(\'wootie\'); }" title="mark this track a request" />';
		$request = '<input checked="checked" type="checkbox" id="request['.$airplayrow[id].']" onclick="setRequest('.$airplayrow[id].')" title="mark this track a request" />';
		$requestcounter++;
	} else {
//	$request = '<img height="16" width="16" src="./themes/' . $theme . '/img/blank.png" alt=" " />';
		$request = '<input type="checkbox" id="request['.$airplayrow[id].']" onclick="setRequest('.$airplayrow[id].')" title="mark this track a request" />';
	}
?>
<!-- widget replacement --> <?php 

if ($q < 3) {
   include('./widgets/traffic_track_full.inc');
} else {
   include('./widgets/traffic_track.inc');
}
?>


<?php
	unset($request);
	$lasttimestamp = $airplayrow[0];
	$q++;
}
?>
<?php
if (!$lasttimestamp) {
	$lasttimestamp = $nowstamp;
}
$traffic_sql = "SELECT * FROM `traffic` WHERE ((`timestamp`<'".mysql_real_escape_string($lasttimestamp)."')  AND (`timestamp`>='".mysql_real_escape_string($three_hours_ago)."' AND `user`='".mysql_real_escape_string($U_id)."') AND (`user`='".$U_id."')) ORDER BY `timestamp` DESC";
$traffic_result = mysql_query($traffic_sql) or die(mysql_error());
while (($traffic_row = mysql_fetch_assoc($traffic_result)) && !(mysql_fetch_row($airplayresult))) {
	//start getting info for traffic log
	//this will give us the proper event name from the DB:
	$eventname = mysql_result(mysql_query("SELECT `name` FROM `event` WHERE `id`='".mysql_real_escape_string($traffic_row[eventtype])."' LIMIT 1"), 0);
	?>
	<?php /* <tr style="background-color: #c0c0c0"><td colspan="2" style="border-bottom: 1px dotted black; vertical-align:middle; text-align:center;"><?=date("h:i", strtotime($traffic_row[timestamp]))?></td><td colspan="2"><?=$eventname?></td><td colspan="5"><?=$traffic_row[comment]?></td><td style="border-bottom: 1px dotted black; vertical-align:middle; text-align:center"><a href="?mode=traffic&do=traffic_down&timestamp=<?=$traffic_row[timestamp]?>&cat=<?=$cat?>" title="Move this traffic item down"><img style="border: 0px;" height="16" width="16" title="Move this traffic item down one space" alt="arrow, move down" src="./themes/<?=$theme?>/img/down.png" /></a><a href="?mode=traffic&do=traffic_edit&timestamp=<?=$traffic_row[timestamp]?>&cat=<?=$cat?>" title="Edit this traffic item"><img style="border: 0px;" height="16" width="16" title="Edit this traffic item" alt="arrow, move down" src="./themes/<?=$theme?>/img/edit.png" /></a><a href="?mode=traffic&do=traffic_delete&timestamp=<?=$traffic_row[timestamp]?>&cat=<?=$cat?>" title="delete this traffic event from the log" onclick="return confirm('Do you really want to delete this traffic log entry?')"><img style="border: 0px;" height="16" width="16" title="delete this logged event" alt="trash, delete" src="./themes/<?=$theme?>/img/trash.png" /></a></td></tr> */ ?>
	<?php
	include('./widgets/traffic_event.inc');
}
?>
<tr><td colspan="6"> totals:</td><td><?=$newcounter?></td><td><?=$oldcounter?></td><td><?=$requestcounter?></td>
</tr></table>
</form>
<!--</td></tr></table> -->
